package com.core.cloudgateway.enums;

import com.core.cloudcommon.CommonResultCode;

/**
 * @author =====Lqj=====
 * @className CloudGatewayResultCode
 * @description 网关异常返回参数
 * @create 2024/11/18 20:18
 **/

public enum CloudGatewayResultCode {


    CODE400001(400001, "token已过期或已失效，请重新登陆"),
    CODE400002(400002, "token为空或不存在，请检查"),
    CODE400003(400003, "token参数异常，请检查");



    private final Integer code;
    private final String msg;

    CloudGatewayResultCode(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    // 获取 code 值
    public Integer getCode() {
        return code;
    }

    // 获取 msg 值
    public String getMsg() {
        return msg;
    }

    /**
     * 通过 code 获取枚举项
     */
    public static CloudGatewayResultCode getByCode(Integer code) {
        if (code == null) {
            throw new IllegalStateException("响应编码不能为空");
        }
        for (CloudGatewayResultCode resultCode : CloudGatewayResultCode.values()) {
            if (resultCode.getCode().equals(code)) {
                return resultCode;
            }
        }
        throw new IllegalStateException("编码不存请重试输入,不存在的编码：" + code);
    }
}
